package com.example.tests;

import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

import java.util.regex.Pattern;

import static org.apache.commons.lang3.StringUtils.join;

public class loginnew {
	private Selenium selenium;

	@Before
	public void setUp() throws Exception {
		WebDriver driver = new FirefoxDriver();
		String baseUrl = "http://mdev34.oilspace.net:8049/";
		selenium = new WebDriverBackedSelenium(driver, baseUrl);
	}

	@Test
	public void testLogin_logout() throws Exception {
		selenium.open("/");
		selenium.type("id=forFocus", "adam");
		selenium.type("name=password", "adam");
		selenium.click("id=login");
		selenium.waitForPageToLoad("30000");
		for (int second = 0;; second++) {
			if (second >= 60) fail("timeout");
			try { if ("To create a new account fill in the details below".equals(selenium.getText("css=div.topTitle"))) break; } catch (Exception e) {}
			Thread.sleep(1000);
		}

		selenium.click("link=Logout");
		selenium.waitForPageToLoad("30000");
		selenium.selectWindow("null");
		assertEquals("Завершение сеанса работы - Aspect Enterprise Solutions", selenium.getTitle());
	}
	// комментарий 

	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
